<?xml version="1.0" encoding="UTF-8"?>
<!--

       Copyright 2006-2019 the original author or authors.

       Licensed under the Apache License, Version 2.0 (the "License");
       you may not use this file except in compliance with the License.
       You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.

-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>The &lt;javaTypeResolver&gt; Element</title>
  <link rel="stylesheet" type="text/css" href="../mbgstyle.css" />
</head>
<body>
<h1>The &lt;javaTypeResolver&gt; Element</h1>
<p>The &lt;javaTypeResolver&gt; element is used to define properties of the Java Type Resolver.
The Java Type Resolver is used to calculate Java types from database column information.
The default Java Type Resolver attempts to make JDBC DECIMAL and NUMERIC types easier
to use by substituting Integral types if possible (Long, Integer, Short, etc.)
If this behavior is undesirable, set the property "forceBigDecimals" to "true".
You can also substitute your own implementation if you want different
behavior than the default.  This element is an optional child element
of the <a href="context.html">&lt;context&gt;</a> element.</p>

<p>Note: if you use the MyBatis3Kotlin runtime, then the generator will automatically convert Java types to their
appropriate Kotlin equivalents when applicable.</p>

<h2>Required Attributes</h2>
<p>None</p>

<h2>Optional Attributes</h2>
<table border="1" cellspacing="0" cellpadding="5">
  <tr>
    <th>Attribute</th>
    <th>Description</th>
  </tr>
  <tr>
    <td valign="top">type</td>
    <td>This can be used to specify a user provided Java Type Resolver.
        The class must implement the interface
        <code>org.mybatis.generator.api.JavaTypeResolver</code>,
        and must have a public default constructor.  The attribute also accepts
        the special value DEFAULT in which case the default implementation will
        be used (this has the same effect as not specifying the type).</td>
  </tr>
</table>

<h2>Child Elements</h2>
<ul>
  <li><a href="property.html">&lt;property&gt;</a> (0..N)</li>
</ul>

<h2>Supported Properties</h2>
<p>This table lists the properties of the default Java type resolver that can be
specified with the <a href="property.html">&lt;property&gt;</a> child element:</p>
<table border="1" cellspacing="0" cellpadding="5">
  <tr>
    <th>Property Name</th>
    <th>Property Values</th>
  </tr>
  <tr>
    <td valign="top">forceBigDecimals</td>
    <td>
      This property is used to specify whether MyBatis Generator should force the use
      of <code>java.math.BigDecimal</code> for DECIMAL and NUMERIC fields,
      rather than substituting integral types when possible.
      The property supports these values:
      <table>
        <tr>
          <th valign="top">false</th>
          <td><i>This is the default value</i>
            <br/>When the property is false or unspecified, the default Java
            type resolver will attempt to make JDBC DECIMAL and NUMERIC types
            easier to work with by substituting Integral types if possible.  The
            substitution rules are as follows:
            <ul>
              <li>If the scale is greater then zero, or the length is greater
                  than 18, then the java.math.BigDecimal type will be used</li>
              <li>If the scale is zero, and the length is 10 through 18, then the Java
                  type resolver will substitute a java.lang.Long.</li>
              <li>If the scale is zero, and the length is 5 through 9, then the Java
                  type resolver will substitute a java.lang.Integer.</li>
              <li>If the scale is zero, and the length is less than 5, then the Java
                  type resolver will substitute a java.lang.Short.</li>
            </ul>
            </td>
        </tr>
        <tr>
          <th valign="top">true</th>
          <td>When the property is true, the Java type resolver will always use
           java.math.BigDecimal if the database column is of type DECIMAL or NUMERIC.</td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td valign="top">useJSR310Types</td>
    <td>
      This property is used to specify whether MyBatis Generator should force the use
      of JSR-310 data types for DATE, TIME, and TIMESTAMP fields, rather than using <code>java.util.Date</code>.
      If true, the types will be resolved as follows:
      <table border="1">
        <tr>
          <th>JDBC Type</th>
          <th>Resolved Java Type</th>
        </tr>
        <tr>
          <td>DATE</td>
          <td><code>java.time.LocalDate</code></td>
        </tr>
        <tr>
          <td>TIME</td>
          <td><code>java.time.LocalTime</code></td>
        </tr>
        <tr>
          <td>TIMESTAMP</td>
          <td><code>java.time.LocalDateTime</code></td>
        </tr>
      </table>
      <p>Note: the type resolver will always resolve the following JSR-310 types regardless of the value of this property:</p>
      <table border="1">
        <tr>
          <th>JDBC Type</th>
          <th>Resolved Java Type</th>
        </tr>
        <tr>
          <td>TIME_WITH_TIMEZONE</td>
          <td><code>java.time.OffsetTime</code></td>
        </tr>
        <tr>
          <td>TIMESTAMP_WITH_TIMEZONE</td>
          <td><code>java.time.OffsetDateTime</code></td>
        </tr>
      </table>
    </td>
  </tr>
</table>

<h2>Example</h2>
<p>This element specifies that we always want to use the java.math.BigDecimal
type for DECIMAL and NUMERIC columns:</p>
<pre>
&lt;javaTypeResolver&gt;
  &lt;property name="forceBigDecimals" value="true" /&gt;
&lt;/javaTypeResolver&gt;
</pre>

</body>
</html>
